﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class SmallGold : MonoBehaviour
{
    public int Gold;
    public Text GoldText;
    void Start()
    {
        Gold = Player.instance.Gold;
       
    }


    // Update is called once per frame
    void Update()
    {

    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name.Equals("Wall"))
        {
            GetComponent<Rigidbody2D>().velocity = new Vector3(Random.Range(-90, 90), Random.Range(0, 90), 0);

            GetComponent<Rigidbody2D>().AddForce(Vector3.up * 200, ForceMode2D.Impulse);
        }
        if (collision.gameObject.name.Equals("Wall1"))
        {
            GetComponent<Rigidbody2D>().AddForce(new Vector3(Random.Range(0, 90) * 2, Random.Range(0, 90), 0), ForceMode2D.Impulse);
        }
        if (collision.gameObject.name.Equals("Wall2"))
        {
            GetComponent<Rigidbody2D>().AddForce(new Vector3(Random.Range(-90, 0) * 2, Random.Range(0, 90), 0), ForceMode2D.Impulse);
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.name.Equals("Player"))
        {
            ShortVoice.instance.PlayVoice("EatGold3");
                Destroy(gameObject);
                DataManager.Instance.Gold += Gold;
                DataManager.Instance.Save();
                GoldAndLv.instance.GengXin();
            
            
        }
    }

}
